package org.jing.ext.jdbc.mybatis.test.mapper;

import org.apache.ibatis.annotations.*;
import org.jing.ext.jdbc.mybatis.param.Params;
import org.jing.ext.jdbc.mybatis.test.dto.UserDto;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2021-08-12 <br>
 */
public interface UserDao {
    @Select("select id, name, password, state, email, tel, insert_date from ut_user where id = #{id}")
    @Results(id="accountMap",value = {
        @Result(id = true, column = "id", property = "id"),
        @Result(column = "name", property = "name"),
        @Result(column = "password",property = "password"),
        @Result(property = "state",column = "state"),
        @Result(property = "email",column = "email"),
        @Result(property = "tel",column = "tel"),
        @Result(property = "insert_date",column = "createDate")
    })
    UserDto queryUserById(@Param("id") int id);

    @Select("select coalesce(max(id), 0) + 1 from ut_user")
    int qryNextId();

    @Update("create table if not exists ut_user (id integer not null, name text not null, password text not null, state text not null, email text not null, tel text not null, insert_date text not null)")
    void enableTable();

    @Insert("insert into ut_user (id, name, password, state, email, tel, insert_date) values (#{p.id}, #{p.name}, #{p.password}, #{p.state}, #{p.email}, #{p.tel}, #{p.insertDate})")
    void createUser(@Param("p") Params params);
}
